﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

namespace Compiler
{
    public class Symbol
    {
        public readonly int ID;

        public readonly string Name;
        public static readonly Symbol Epsilon = new Symbol(-1, "EPSILON");
        public static readonly Symbol EOF = new Symbol(-2, "$");

        public Symbol(int ID, string Name)
        {
            this.ID = ID;
            this.Name = Name;
        }

        public override string ToString()
        {
            return Name;
        }

        public class SymbolEqualityComparer : IEqualityComparer<Symbol>
        {
            public bool Equals(Symbol x, Symbol y)
            {
                return ReferenceEquals(x,y) ||  x.Name == y.Name && x.ID == y.ID && x.GetType() == y.GetType();
            }

            public int GetHashCode(Symbol obj)
            {
                return obj.Name.GetHashCode() + 17 * obj.ID.GetHashCode();
            }
        }
    }
}
